home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / du_lib / xacc2 / xacc2.txt < prev    next >
Text File  |  1993-02-01  |  25KB  |  502 lines

  1. XAcc: a communication protocol for GEM applications
  2. ===================================================
  3.  
  4. (last revision: November 28, 1992)
  5.  
  6.  
  7. The XAcc protocol was originally designed for non-multitasking versions of 
  8. GEM to allow data exchange between the main application and any number of 
  9. accessories. Since the AES did not provide a function to find the 
  10. application ids (apids) of other applications without knowing their names, 
  11. XAcc had to rely on the undocumented feature that the main application 
  12. always has the apid 0. Therefore XAcc in its present form does not work in 
  13. a multitasking environment. However, AES 4.0 provides the new function 
  14. appl_search(), which allows any application to find the apids of all other 
  15. applications running concurrently. This makes it possible to design a 
  16. modified XAcc that does not use any 'dirty tricks'. This document contains 
  17. a proposal for such a modified XAcc; the changes with respect to the 
  18. previous definition are small and modifying an existing XAcc-based 
  19. application should be a matter of minutes. Since single-tasking TOS will 
  20. still be with us for a while, applications are encouraged to implement both 
  21. 'traditional' and 'modern' XAcc, depending on the version number of the AES.
  22.  
  23.  
  24. Purpose
  25. -------
  26.  
  27. The GEM AES functions appl_write() and appl_read() can be used to exchange 
  28. data between GEM applications running concurrently. In practice however, 
  29. some problems need to be solved to make good use of these two functions:
  30.  
  31. - There are no standard messages for exchanging data. Their definition is 
  32.   the main goal of XAcc.
  33.  
  34. - appl_write() needs the receiver's application identifier (apid). The 
  35.   only way to get this (before AES 4.0) is to call appl_find(), which 
  36.   needs the receiver's name. Thus communication is only possible if 
  37.   the sender knows the receiver's name.
  38.   This problem is solved in AES 4.0 by the introduction of the function 
  39.   appl_search().
  40.  
  41. - The main application does not know when an accessory is activated or 
  42.   deactivated. This would often be useful, for example if the main 
  43.   application changes system variables that could affect the accessory's 
  44.   behaviour. If the main application were informed before the accessory 
  45.   gains control, it could reset those to their old values and change 
  46.   them back after the accessory is finished.
  47.   Another advantage would be that after an accessory has been called, 
  48.   the main application could check if something has been written to the 
  49.   clipboard or if other changes to the environment have been made.
  50.  
  51.   With multitasking GEM, the situation has changed in several important 
  52.   ways. The possibility of using several 'main' applications in parallel 
  53.   makes it even more undesirable to let them directly manipulate system 
  54.   variables and the like; nevertheless there will probably always remain 
  55.   some purposes that require such methods. On the other hand, at least 
  56.   for applications using windows (the preferred method to get the most 
  57.   out of a multitasking system) it is now possible to detect changes 
  58.   of the active application by interpreting the new AES messages 
  59.   WM_ONTOP and WM_UNTOPPED. Therefore it is not considered necessary 
  60.   for XAcc to provide additional means to achieve this.
  61.  
  62. The communications protocol described in this document solves all these 
  63. problems. It was designed for two distinct purposes:
  64.  
  65. - Exchanging data of standard types between programs that have no 
  66.   information about each other.
  67.  
  68. - Exchanging data between specific applications known to each other. 
  69.   The standard protocol ensures that program combinations from 
  70.   different vendors do not interfere with each other.
  71.  
  72. A potential problem caused by this protocol should be mentioned at this 
  73. point: for single-tasking GEM versions, it relies on the currently 
  74. undocumented fact that the main application's apid is always zero. Without 
  75. this assumption there is no way to exchange data without using appl_find(). 
  76. Although this fact is not documented, it holds for all single-tasking 
  77. versions of GEM in existence until now, both for MS-DOS and the Atari ST 
  78. (this information was confirmed by Digital Research Germany). Of course 
  79. the main application's apid may be different in future versions, although 
  80. there is no reason to change the current behaviour for single-tasking 
  81. systems. For AES 4.0 (and later) the above assumption is not needed anyway, 
  82. so no compatibility problems are to be expected in the future.
  83.  
  84. A further requirement is that all programs not using this protocol must 
  85. ignore its messages. This should not be a serious problem, as all GEM 
  86. applications should ignore messages they do not understand. At the time 
  87. of writing no programs are known to violate this rule.
  88.  
  89.  
  90. XAcc message groups
  91. -------------------
  92.  
  93. [Note: The "levels" used in previous XAcc versions have been replaced
  94.  by this new concept. Compatibility issues are discussed in a special
  95.  section at the end of this document.]
  96.  
  97. Both main applications and accessories can have widely different needs for 
  98. communication with other programs. Therefore XAcc defines several groups 
  99. of related messages that deal with a certain range of data types. 
  100. The message groups always indicate the messages understood by a 
  101. program, not the messages it might send to other ones. If a program 
  102. supports a certain message group, it must correctly respond to all 
  103. corresponding messages, whether it can actually use the supplied data 
  104. or not.
  105.  
  106. In addition to message groups, there are the so-called "basic messages", 
  107. which must be supported by any XAcc-aware program, and program-specific
  108. so-called "special messages".
  109.  
  110. The basic messages deal solely with identification, but no real data 
  111. exchange. They are already sufficient for programs that either do not 
  112. exchange data with others at all or use only special messages to 
  113. communicate with a number of other specific programs.
  114.  
  115. Message group 1 specifies the exchange of ASCII-format character data.
  116.  
  117. Message group 2 deals with the exchange of drawings and pictures using 
  118. the GEM metafile format and the GEM bit-image file format.
  119.  
  120. Future extensions might include sound or spreadsheet data. In addition,
  121. a message group could be defined to handle command interchange between
  122. applications, e.g. for a "drag&drop" protocol.
  123.  
  124.  
  125. XAcc messages
  126. -------------
  127.  
  128. There are two kinds of XAcc messages: standard messages, which must be 
  129. understood by every participating program, and special messages intended 
  130. for communications between specific program combinations. The standard 
  131. messages have numbers ranging from 0x400 to 0x7ff, special messages start 
  132. from 0x800. The latter ones may only be sent after the receiver has been 
  133. identified and is known to understand them. The following description is 
  134. only concerned with standard messages.
  135. In addition to XAcc standard messages, the AES messages normally sent 
  136. by the screen manager may be used. The most useful ones are AC_OPEN 
  137. and MN_SELECTED; the latter one requires a knowledge of the receiver 
  138. and therefore belongs to the special messages.
  139.  
  140.  
  141. Basic messages
  142. --------------
  143.  
  144. ACC_ID = 0x400
  145. ACC_OPEN = 0x401
  146. ACC_CLOSE = 0x402
  147. ACC_ACC = 0x403
  148. ACC_EXIT = 0x404
  149.  
  150. These messages provide XAcc initialization and organization. This is 
  151. the only part of XAcc which has to be implemented in a different way for 
  152. single- and multi-tasking GEM versions. Note that the procedure 
  153. described for 'multitasking' actually only depends on the existence of 
  154. appl_search() and hence on an AES version number >= 4.0. If some 
  155. future single-tasking AES supports appl_search(), the "multitasking" 
  156. initialization should be used. Multitasking AES versions with a version 
  157. number < 4.0 should never exist; to be on the safe side, applications 
  158. should not attempt to use XAcc if such a situation is detected.
  159.  
  160. I) Single-tasking GEM versions
  161.  
  162. The communication between the main application and the accessories is 
  163. initiated in the following way:
  164.  
  165. 1) When a main application is started (or terminated), all accessories 
  166.    receive an AC_CLOSE message from the AES screen manager. In response 
  167.    they must send an identification to the main application according 
  168.    to the following format:
  169.      msgbuf[0]:  ACC_ID
  170.      msgbuf[1]:  sender's apid
  171.      msgbuf[2]:  length of the message - 16, giving 0
  172.      msgbuf[3]:  program version number and message groups
  173.      msgbuf[4] and msgbuf[5]:   pointer to sender's name
  174.      msgbuf[6]:  menu number (menu_id) as returned by menu_register()
  175.      msgbuf[7]:  reserved (see ACC_ACC)
  176.    The low byte of msgbuf[3] contains a bitmap indicating which message
  177.    groups are understood by the sender. Bit zero is set for message
  178.    group 1, bit one for message group 2, and so on. This is independent 
  179.    of the message types which the sender might itself send to others. The 
  180.    sender of a message must ensure that it is understood by the receiver. 
  181.    The high byte is used to indicate a program version number using an 
  182.    arbitrary encoding scheme.
  183.    The pointer to the sender's name is stored in a machine-dependent 
  184.    format. The name itself is a character string following C conventions, 
  185.    i.e. a string of characters terminated by a zero byte. To avoid name 
  186.    conflicts, long names are preferred to short abbreviations. The name 
  187.    must be available at the given address at any time, it may not be 
  188.    removed after initialisation. As the version number is stored in 
  189.    msgbuf[3], it should not occur again in the name.
  190.    [Note: see the section "Extended names" for more details on names.]
  191.    Accessories using more than one menu entry must issue one ACC_ID 
  192.    message for each entry used. Accessories without a menu entry must 
  193.    use a number of -1.
  194.  
  195. Since msgbuf[1] and msgbuf[2] have the same meaning for all message 
  196. types, they are no longer mentioned from now on.
  197.  
  198. 2) In response to an ACC_ID message the main application sends an 
  199.    identification back to the accessory. The format is identical, except 
  200.    that there ist no menu number and thus msgbuf[6] can be used for any 
  201.    other purpose if neccessary. The same applies to msgbuf[7].
  202.  
  203. 3) In addition to the ACC_ID message, the main application informs all 
  204.    previously registered accessories about the new one by sending them 
  205.    the message
  206.      msgbuf[0]:  ACC_ACC
  207.      msgbuf[3]:  program version number and message groups
  208.      msgbuf[4] and msgbuf[5]:   pointer to accessory's name
  209.      msgbuf[6]:  accessory's menu number (menu_id)
  210.      msgbuf[7]:  accessory's apid
  211.  
  212. 4) An accessory receiving the ACC_ACC message from the main application 
  213.    sends an ACC_ID message to the thereby registered accessory, identical 
  214.    to the one previously sent to the main application.
  215.  
  216. 5) When an accessory is activated by receiving an AC_OPEN message, it 
  217.    sends the following message to the main application:
  218.      msgbuf[0]:  ACC_OPEN
  219.    Just before the accessory returns control to another program, it 
  220.    sends the message
  221.      msgbuf[0]:  ACC_CLOSE
  222.    When receiving ACC_OPEN, the main application restores all system 
  223.    variables it has changed to their original values (if possible and 
  224.    neccessary). After receiving ACC_CLOSE, it may set them again to any 
  225.    desired value.
  226.    Accessories should change system variables only after sending 
  227.    ACC_OPEN and restore them before ACC_CLOSE.
  228.  
  229.    There have been some problems with the implementation of ACC_OPEN and 
  230.    ACC_CLOSE that should be mentioned. The system was designed with 
  231.    window-less accessories in mind, i.e. accessories that only display 
  232.    a dialog box. For these accessories, the above procedure is 
  233.    well-defined. Accessories that use windows however have no way to 
  234.    find out if they have been activated or deactivated, because they 
  235.    do not receive a message to indicate this (starting from AES 4.0, 
  236.    this problem is solved). Therefore such accessories must be careful 
  237.    with ACC_OPEN and ACC_CLOSE. The most important thing is to guarantee 
  238.    that ACC_OPEN and ACC_CLOSE always occur in pairs, and that in between 
  239.    no other program gains control. How exactly this is implemented 
  240.    depends on the specific application. Sometimes the best implementation 
  241.    is not to use ACC_OPEN and ACC_CLOSE at all.
  242.  
  243. After initialization is completed, all participating programs know the 
  244. identity of all other ones, either by receiving an ACC_ID message or by 
  245. receiving an ACC_ACC message. The main application is always informed 
  246. about accessory activities. If in addition it proves neccessary to 
  247. inform one accessory about the activation of another one, this can be 
  248. accomplished by sending special messages (starting from 0x800).
  249.  
  250. II) Multitasking GEM versions
  251.  
  252. The initialization procedure is much simpler in this case. Any application, 
  253. i.e. both 'standard' applications and accessories, uses appl_search() to 
  254. detect all currently running AES processes when it is started. To each 
  255. application or accessory (i.e. everything but system processes) it sends 
  256. an ACC_ID message:
  257.   msgbuf[0]:  ACC_ID
  258.   msgbuf[1]:  sender's apid
  259.   msgbuf[2]:  length of the message - 16, giving 0
  260.   msgbuf[3]:  program version number and message groups
  261.   msgbuf[4] and msgbuf[5]:   pointer to sender's name
  262.   msgbuf[6]:  menu number (menu_id) as returned by menu_register()
  263.   msgbuf[7]:  reserved
  264. The low byte of msgbuf[3] contains a bitmap indicating which message
  265. groups are understood by the sender. Bit zero is set for message
  266. group 1, bit one for message group 2, and so on. This is independent 
  267. of the message types which the sender might itself send to others. The 
  268. sender of message must ensure that it is understood by the receiver. The 
  269. high byte is used to indicate a program version number using an 
  270. arbitrary encoding scheme.
  271. The pointer to the sender's name is stored in a processor-dependent 
  272. format. The name itself is a string of characters terminated by two zero 
  273. byte. To avoid name conflicts, long names are preferred to short 
  274. abbreviations. The name must be available at the given address at any time, 
  275. it may not be removed after initialization. It must also reside in 
  276. globally accessible memory. As the version number is stored in msgbuf[3], 
  277. it should not occur again in the name.
  278. [Note: see the section "Extended names" for more details on names.]
  279. Applications using more than one menu entry must issue one ACC_ID 
  280. message for each entry used. Accessories without a menu entry must 
  281. use a number of -1.
  282.  
  283. When receiving an ACC_ID message, an application replies by sending a 
  284. message of the same format to the original sender, the only difference
  285. being that ACC_ACC is used instead of ACC_ID. Applications with 
  286. several menu entries must again send one message for each entry.
  287.  
  288. The messages ACC_OPEN and ACC_CLOSE are not used in multitasking 
  289. systems.
  290.  
  291. Note: The only difference between ACC_ID and ACC_ACC for multitasking
  292. systems is that an application receiving ACC_ID sends ACC_ACC as a
  293. reply, whereas no reply is sent on receiving ACC_ACC. This prevents
  294. applications from sending ACC_ID to each other indefinitely.
  295. Obviously the name ACC_ACC has lost its original meaning and
  296. probably should be changed. But since the symbolic names do not influence
  297. the actual behaviour of any program, this is not really important at all.
  298.  
  299. Since in a multitasking environment every participating application 
  300. can terminate, some means must be provided to tell other applications 
  301. about this. Therefore the message ACC_EXIT has been added to the list
  302. of level 0 messages. Before terminating, any application sends
  303.   msgbuf[0]:  ACC_ID
  304.   msgbuf[1]:  sender's apid
  305.   msgbuf[2]:  length of the message - 16, giving 0
  306. to all applications that have ever registered themselves by sending
  307. ACC_ID or ACC_ACC.
  308.  
  309.  
  310. Extended names
  311. --------------
  312.  
  313. Experience with XAcc has shown that it would often be useful to have more
  314. information about an application than specified with ACC_ID messages. 
  315. For example it is sometimes useful to check for a special feature that 
  316. is not unique to a single program, but to several similar ones. This 
  317. was the motivation for the introduction of "extended names".
  318.  
  319. An "extended name" is a character string of the format
  320. 'name'\0XDSC\0'string'\0'string'\0...'string'\0\0
  321. i.e. a "standard" name followed by the string "XDSC" (for "eXtended 
  322. DeSCription"), followed by a list of strings containing additional 
  323. information. The end of the list is marked by an additional zero byte.
  324.  
  325. Each information string indicates by its first byte what kind of 
  326. information it contains. Currently the following types are defined:
  327.  
  328. '1' - application type (human-readable)
  329.       The text following this byte (an ASCII-1, 0x31) should roughly 
  330.       specify the type of application, e.g. "word processor" or 
  331.       "spreadsheet". The purpose is for applications to present 
  332.       this information to the user to let him/her decide where data 
  333.       should go. This is not the place for advertising hype; a word 
  334.       processor should call itself "word processor" and not "document 
  335.       editing and design system".
  336.       It should be clear that the text should be understandable for end 
  337.       users, especially it should be in the language used for the user 
  338.       interface.
  339.  
  340. '2' - application type (machine-readable)
  341.       Currently defined are:
  342.       "WP" - word processor
  343.       "DP" - DTP
  344.       "ED" - text editor
  345.       "DB" - database
  346.       "SS" - spreadsheet
  347.       "RG" - raster graphics application
  348.       "VG" - vector graphics application
  349.       "GG" - general graphics application
  350.       "MU" - music application
  351.       "CD" - CAD
  352.       "DC" - data communication
  353.       "DT" - desktop
  354.       "PE" - programming environment
  355.  
  356. 'X' - extended features
  357.       This string is used to indicate special communication capabilities 
  358.       of an application. It can be used to give more specific information 
  359.       than the message groups understood. Since this information is meant 
  360.       to be used by other applications rather than end users, short 
  361.       abbreviations are sufficient.
  362.  
  363. 'N' - generic name
  364.       Often several related, but not completely identical, applications 
  365.       have different names. Marketing requirements may even dictate 
  366.       changes of the "official" brand names, making them unsuitable 
  367.       for a "technical" identification. In such cases a "generic" name
  368.       for all these programs can be specified, which is mainly used 
  369.       by other programs wishing to use special messages.
  370.  
  371. The "normal" name should be the "official" name of the program, just as it 
  372. is used on the package, in the manual, and in similar places. It should 
  373. be presentable to the user to let him/her decide where to send data.
  374.  
  375. Example: The address database "That's Address" identifies itself with the 
  376. extended name (in C syntax)
  377. "That's Address\0XDSC\01database\02DB\0XMM\0XSU\0",
  378. indicating that it is a database with features "MM" and "SU". The first 
  379. one indicates a special mail merge mode, the second one the possibility 
  380. of retrieving data by sending the key via ACC_TEXT.
  381. (Further information on this program can be obtained from its manual.)
  382.  
  383.  
  384. Message group 1
  385. ---------------
  386.  
  387. ACC_ACK = 0x500
  388. ACC_TEXT = 0x501
  389. ACC_KEY = 0x502
  390.  
  391.  
  392. 1) Transmitting text data:
  393.      msgbuf[0]:  ACC_TEXT
  394.      msgbuf[4] and msgbuf[5]:   pointer to text
  395.    The text may contain all printable ASCII characters (code >= 32) and the 
  396.    following control codes:
  397.      0x09  TAB (may be interpreted as a space by the receiver)
  398.      0x0A  LF  (usually ignored by receiver)
  399.      0x0D  CR  (used to mark an end-of-line (or end-of paragraph)
  400.    Other control codes may only be used if the receiver is known to 
  401.    understand them. The text is terminated by a zero byte.
  402.    After the text has been interpreted completely, the receiver 
  403.    acknowledges by sending
  404.      msgbuf[0]:  ACC_ACK
  405.      msgbuf[3]:  0 if the text was simply ignored, 1 if it was used in 
  406.                  some sensible way
  407.    The sender of a text message may not change the text nor send any 
  408.    other text messages to the same receiver until is has received the 
  409.    acknowledge.
  410.    The sender must make sure that the memory used to store the text 
  411.    is globally accessible.
  412.    The receiver should normally interpret the text as if it were typed 
  413.    from the keyboard. A word processor would for example insert it into 
  414.    the currently edited document (this implies using CR as an end-of- 
  415.    paragraph mark), a command line interpreter would interpret the text 
  416.    as a command (which implies using CR as an end-of-line mark).
  417.  
  418. 2) Simulation of a key press:
  419.      msgbuf[0]:  ACC_KEY
  420.      msgbuf[3]:  scan code of the simulated key and corresponding 
  421.                  ASCII code (as returned by evnt_keybd())
  422.      msgbuf[4]:  state of the SHIFT keys (as returned by Kbshift())
  423.    This message should be regarded identical to a keyboard event. It can 
  424.    be used to send control commands to a receiver which might have 
  425.    been issued from the keyboard. Of course this requires a knowledge 
  426.    of the receiver as no standard keyboard command sets exist. It should 
  427.    be noted that the receiver is free to use only the ASCII code or the 
  428.    scan code, or both of them.
  429.    This message is acknowledged after its interpretation with
  430.      msgbuf[0]:  ACC_ACK
  431.      msgbuf[3]:  0 if ACC_KEY was ignored or a given command was not 
  432.                  understood, 1 if some action was taken.
  433.  
  434. To prevent a deadlock if a program does not properly acknowledge a 
  435. message, the sender should have some way to recover. An accessory 
  436. could for example stop waiting for an acknowledgement after the next 
  437. AC_OPEN, a main application might time out after a sufficiently long 
  438. period.
  439.  
  440.  
  441. Message group 2
  442. ---------------
  443.  
  444. ACC_META = 0x503
  445. ACC_IMG = 0x504
  446.  
  447. These message are used to exchange drawings and pictures. Only the file 
  448. formats defined in the GEM documentation are used; they are sufficient 
  449. to meet most requirements, and any GEM application should be able to 
  450. handle them anyway.
  451.  
  452. 1) Sending a metafile:
  453.      msgbuf[0]:  ACC_META
  454.      msgbuf[3]:  1 for the final part, 0 otherwise
  455.      msgbuf[4] and msgbuf[5]:   pointer to data
  456.      msgbuf[6] and msgbuf[7]:   length of data (32 bit longword)
  457.    The metafile data is sent in the same format as they would be stored 
  458.    on disk. As metafiles can become quite large and especially 
  459.    accessories often do not have sufficient memory to store them, a 
  460.    file can be sent in several pieces. The receiver has to take care 
  461.    of assembling all parts to restore the original data, if neccessary 
  462.    by writing the parts to a file. The last part of a file is marked 
  463.    by msgbuf[3]=1. The sender may send no other data between the parts 
  464.    of a file. msgbuf[6] and msgbuf[7] contain the length of the part 
  465.    being sent, not the total length.
  466.    The receiver acknowledges each part as described for level 1.
  467.    As for text messages, the sender must make sure that the data to 
  468.    be transferred is stored in globally accessible memory.
  469.  
  470. 2) Sending a bit image file:
  471.      msgbuf[0]: ACC_IMG
  472.    otherwise identical to 1)
  473.  
  474.  
  475.  
  476. Compatibility considerations
  477. ----------------------------
  478.  
  479. There are two major changes with respect to the original XAcc definition:
  480.  
  481. 1) "Levels" have been replaced by "message groups".
  482.    The motivation for this change was that the classification according 
  483.    to exchangeable data types was not really a hierarchical one; there 
  484.    is no reason why a programm accepting graphics should also be able to 
  485.    understand text. The new scheme makes no such arbitrary assumptions. 
  486.  
  487.    There is only one situation in which a possible incompatibility could 
  488.    occur: an application following the "old" convention encounters a 
  489.    "new" application and one of them indicates 2 in the level/message 
  490.    group byte. This would be interpretes as "graphics only" by one and 
  491.    as "graphics and text" by the other. Since the number of level-2 
  492.    applications was always extremely small (in fact, the author knows 
  493.    only of a single one), this should be no problem in practice.
  494.  
  495. 2) Extended names have been introduced.
  496.    This could lead to a problem in the extremely unlikely case of an 
  497.    "old" application using a name string which is accidentally followed 
  498.    by "XDSC".
  499.  
  500. In any case it is expected that most applications will be converted to 
  501. the new rules soon, if only to support MultiTOS.
  502.